package com.shyt.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.shyt.dao.SysDepartmentVo;
import com.shyt.dao.SysRoleVo;
import com.shyt.dao.SysUserVo;
import com.shyt.dao.UserLabelVo;
import com.shyt.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysUserServiceImpl {

    @Autowired
    SysUserMapper sysUserDao;


    public IPage<SysUserVo> selectSysUsers(IPage<SysUserVo> ipage){
        return  sysUserDao.selectSysUsers(ipage);
    }

    public List<SysUserVo> selectSysUserByUsername(String userName){
        return  sysUserDao.selectSysUserByUsername(userName);
    }

    public List<SysUserVo> selectAllUsers(SysUserVo selectAllUsers) {
        return  sysUserDao.selectAllUsers(selectAllUsers);
    }

    public void deleteYh(SysUserVo deleteYh) {
        sysUserDao.deleteYh(deleteYh);
    }

    public List<SysDepartmentVo> selectDepartmentsForUser() {
        return  sysUserDao.selectDepartmentsForUser();
    }

    public void addUser(SysUserVo sysUserVo) {
        sysUserDao.addUser(sysUserVo);
    }

    public List<SysRoleVo> selectAllRoles() {
        return sysUserDao.selectAllRoles();
    }
    public List<SysRoleVo> selectAllRolesHasAl(Long id) {
        return sysUserDao.selectAllRolesHasAl(id);
    }

    public void addRoles(List<UserLabelVo> roles, Long id) {
        sysUserDao.deleteByUserId(id);
        if (CollectionUtils.isNotEmpty(roles)){
            roles.stream().forEach(item->{
                sysUserDao.addRoles(item,id);
            });
        }


    }

    public void editUser(SysUserVo sysUserVo) {
        sysUserDao.editUser(sysUserVo);
    }
}
